﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using HumanResourceSystem.Models;

namespace HumanResourceSystem.Controllers
{
    public class EmployeeEvaluationsController : Controller
    {
        private ApplicationDbContext db = new ApplicationDbContext();

        // GET: EmployeeEvaluations
        [Authorize]
        public ActionResult Index(string SearchString, string SearchID)
        {
            var employees = from e in db.EmployeeEvaluations
                            select e;
            if (!String.IsNullOrEmpty(SearchString))
            {
                employees = employees.Where(s => s.Name.Contains(SearchString));
            }
            if (!String.IsNullOrEmpty(SearchID))
            {
                employees = employees.Where(s => s.IDCard.Contains(SearchID));
            }

            return View(employees);
        }

        // GET: EmployeeEvaluations/Details/5
        public ActionResult Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            EmployeeEvaluation employeeEvaluation = db.EmployeeEvaluations.Find(id);
            if (employeeEvaluation == null)
            {
                return HttpNotFound();
            }
            return View(employeeEvaluation);
        }

        // GET: EmployeeEvaluations/Create
       
        public ActionResult Create()
        {
            return View();
        }

        // POST: EmployeeEvaluations/Create
        // 为了防止“过多发布”攻击，请启用要绑定到的特定属性，有关 
        // 详细信息，请参阅 http://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "Id,IDCard,Name,Text,NameEe,Date")] EmployeeEvaluation employeeEvaluation)
        {
            if (ModelState.IsValid)
            {
                db.EmployeeEvaluations.Add(employeeEvaluation);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(employeeEvaluation);
        }

        // GET: EmployeeEvaluations/Edit/5
       
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            EmployeeEvaluation employeeEvaluation = db.EmployeeEvaluations.Find(id);
            if (employeeEvaluation == null)
            {
                return HttpNotFound();
            }
            return View(employeeEvaluation);
        }

        // POST: EmployeeEvaluations/Edit/5
        // 为了防止“过多发布”攻击，请启用要绑定到的特定属性，有关 
        // 详细信息，请参阅 http://go.microsoft.com/fwlink/?LinkId=317598。
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "Id,IDCard,Name,Text,NameEe,Date")] EmployeeEvaluation employeeEvaluation)
        {
            if (ModelState.IsValid)
            {
                db.Entry(employeeEvaluation).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(employeeEvaluation);
        }

        // GET: EmployeeEvaluations/Delete/5
        
        public ActionResult Delete(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            EmployeeEvaluation employeeEvaluation = db.EmployeeEvaluations.Find(id);
            if (employeeEvaluation == null)
            {
                return HttpNotFound();
            }
            return View(employeeEvaluation);
        }

        // POST: EmployeeEvaluations/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            EmployeeEvaluation employeeEvaluation = db.EmployeeEvaluations.Find(id);
            db.EmployeeEvaluations.Remove(employeeEvaluation);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
